package com.glsc.ngateway.common.base.converter.platform;

import com.alibaba.excel.util.CollectionUtils;
import com.glsc.ngateway.common.api.flowable.dto.FlowFormNewDeviceStandardDetailDto;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.flow.cmdb.FlowFormNewDeviceStandardDetail;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author xuchang
 */
public class FlowFormNewDeviceStandardDetailConverter {

    public static FlowFormNewDeviceStandardDetailDto do2Dto(FlowFormNewDeviceStandardDetail domain) {
        if (Objects.isNull(domain)) {
            return null;
        }
        FlowFormNewDeviceStandardDetailDto dto = FlowFormNewDeviceStandardDetailMapper.INSTANCE.do2Dto(domain);
        dto.setCpuStandard(CmdbCpuStandardConverter.do2Dto(domain.getCpuStandard()));
        dto.setMemoryStandard(CmdbMemoryStandardConverter.do2Dto(domain.getMemoryStandard()));
        dto.setDiskStandardRelate(FlowFormNewDeviceDiskStandardDetailConverter.do2Dto(domain.getDiskStandardRelate()));
        dto.setPartStandardRelate(FlowFormNewDevicePartStandardDetailConverter.do2Dto(domain.getPartStandardRelate()));
        return dto;
    }

    public static List<FlowFormNewDeviceStandardDetailDto> do2Dto(List<FlowFormNewDeviceStandardDetail> domainList) {
        return CollectionUtils.isEmpty(domainList) ? java.util.Collections.emptyList() : domainList.stream().map(FlowFormNewDeviceStandardDetailConverter::do2Dto).collect(Collectors.toList());
    }

    public static FlowFormNewDeviceStandardDetail dto2Do(FlowFormNewDeviceStandardDetailDto dto) {
        if (Objects.isNull(dto)) {
            return null;
        }
        FlowFormNewDeviceStandardDetail domain = FlowFormNewDeviceStandardDetailMapper.INSTANCE.dto2Do(dto);
        domain.setCpuStandard(CmdbCpuStandardConverter.dto2Do(dto.getCpuStandard()));
        domain.setMemoryStandard(CmdbMemoryStandardConverter.dto2Do(dto.getMemoryStandard()));
        domain.setDiskStandardRelate(FlowFormNewDeviceDiskStandardDetailConverter.dto2Do(dto.getDiskStandardRelate()));
        domain.setPartStandardRelate(FlowFormNewDevicePartStandardDetailConverter.dto2Do(dto.getPartStandardRelate()));
        return domain;
    }

    public static List<FlowFormNewDeviceStandardDetail> dto2Do(List<FlowFormNewDeviceStandardDetailDto> dtoList) {
        return CollectionUtils.isEmpty(dtoList) ? java.util.Collections.emptyList() : dtoList.stream().map(FlowFormNewDeviceStandardDetailConverter::dto2Do).collect(Collectors.toList());
    }

    @Mapper(componentModel = "spring")
    public interface FlowFormNewDeviceStandardDetailMapper {

        FlowFormNewDeviceStandardDetailMapper INSTANCE = Mappers.getMapper(FlowFormNewDeviceStandardDetailMapper.class);

        FlowFormNewDeviceStandardDetailDto do2Dto(FlowFormNewDeviceStandardDetail domain);

        List<FlowFormNewDeviceStandardDetailDto> do2Dto(List<FlowFormNewDeviceStandardDetail> domain);

        FlowFormNewDeviceStandardDetail dto2Do(FlowFormNewDeviceStandardDetailDto dto);

        List<FlowFormNewDeviceStandardDetail> dto2Do(List<FlowFormNewDeviceStandardDetailDto> dto);
    }
}
